package deepr.core;

import deepr.anno.Property;
import deepr.anno.SchemaType;
import deepr.exception.DeeprAssert;
import deepr.exception.DeeprException;
import lombok.Data;

import java.util.HashMap;

@Data
public class SchemaData {

  private String name;
  private Class<?> schema;
  private String primaryKey;
  private String object;
  private SchemaType schemaType;
  private HashMap<String, PropertyData> fields = new HashMap<>();
  private Class<?> handler;
  private HashMap<String, SchemaData> relations = new HashMap<>();

  public <T> Class<T> getSchema() {
    return (Class<T>) schema;
  }

//  public void setObject() {
//    object = name.toLowerCase();
//  }

  public void addRelationSchemaData(String relation, SchemaData schemaData) {
    relations.put(relation, schemaData);
  }

  public SchemaData getRelationSchemaData(String relation) {
    return relations.get(relation);
  }

  public HashMap<String, PropertyData> getRelationFields(String relation) {
    return getRelationSchemaData(relation).getFields();
  }

  public PropertyData getPropertyData(String property) {
    PropertyData p = fields.get(property);
    return p;
  }

  public void putPropertyData(String name, PropertyData propertyData) {
    fields.put(name, propertyData);
  }

}
